/*
 * @Author: 张久冬
 * @Date: 2022-01-06 09:52:52
 * @
# Description:
 */
import { Module } from 'vuex'
import { IRootState } from '../../type'
import { IdashboardState } from './type'
import {
  getCategoryGoodsCount,
  getCategoryAddressGoodsSale,
  getCategoryGoodsFavor,
  getCategoryGoodsSale
} from '@/service/main/analysis/analysis'

const dashboardModule: Module<IdashboardState, IRootState> = {
  namespaced: true,
  state() {
    return {
      categoryGoogsCount: [],
      categoryGoogsSale: [],
      categoryGoogsFavor: [],
      addressGoodsSale: []
    }
  },
  mutations: {
    changeCategoryGoodsCount(state, categoryGoogsCount) {
      state.categoryGoogsCount = categoryGoogsCount
    },
    changeCategoryGoodsSale(state, categoryGoogsSale) {
      state.categoryGoogsSale = categoryGoogsSale
    },
    changeCategoryGoodsFavor(state, categoryGoogsFavor) {
      state.categoryGoogsFavor = categoryGoogsFavor
    },
    changeCategoryAddressGoodsSale(state, addressGoodsSale) {
      state.addressGoodsSale = addressGoodsSale
    }
  },
  actions: {
    async getDashBoardDataAction({ commit }) {
      const categoryCountRseult = await getCategoryGoodsCount()
      commit('changeCategoryGoodsCount', categoryCountRseult.data)

      const categorySaleRseult = await getCategoryGoodsSale()
      commit('changeCategoryGoodsSale', categorySaleRseult.data)

      const categoryFavorRseult = await getCategoryGoodsFavor()
      commit('changeCategoryGoodsFavor', categoryFavorRseult.data)

      const categoryAddressGoodsSaleRseult = await getCategoryAddressGoodsSale()
      commit(
        'changeCategoryAddressGoodsSale',
        categoryAddressGoodsSaleRseult.data
      )
    }
  }
}
export default dashboardModule
